<?php 


$username = isset($_POST['username']) ? $_POST['username'] : '';

if($username){

	$preg = "/^[a-z][a-z0-9]{5,7}$/";

	$c = preg_match($preg, $username);

	if(!$c){
		$arr = array(
			'error'=>1,
			'info'=>'用户名必须是6-8位'
			);
		echo json_encode($arr);
	}else{

		$users = include './user.php';

		foreach ($users as $key => $user) {

			if($user['username']==$username){
				$arr = array(
					'error'=>1,
					'info'=>'用户名已存在'
					);
				echo json_encode($arr);
				exit;
			}
			
		}

		$arr = array(
			'error'=>0,
			'info'=>'用户名可以用'
			);
		echo json_encode($arr);

	}


}else{

	$arr = array(
			'error'=>1,
			'info'=>'用户名不能为空'
			);
		echo json_encode($arr);

}


 ?>